﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace IndirectX
{
    public class BitExtensions
    {
        public static uint DecodeValue(uint value, byte start, byte end)
        {
            uint mask = GenerateMask(start, end);
            int shift = start;

            return (value & mask) >> shift;
        }

        private static uint GenerateMask(byte start, byte end)
        {
            uint mask = 0;
            for (int i = start; i <= end; i++)
                mask |= (uint)System.Math.Pow(2, i);
            return mask;
        }
    }
}
